package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.DailyCatalog;
import cn.wolfcode.trip.base.query.DailyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IDailyCatalogService;
import cn.wolfcode.trip.base.service.IDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/dailyCatalog")
public class DailyCatalogController {
    @Autowired
    private IDailyCatalogService dailyCatalogService;
    @Autowired
    private IDailyService dailyService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") DailyCatalogQueryObject qo, Model model) {
        //按照大攻略和序列排序
        qo.setOrderBy("sc.daily_id, sc.sequence desc");
        model.addAttribute("pageInfo", dailyCatalogService.query(qo));
        model.addAttribute("dailyIds", dailyService.listEnable());
        return "dailyCatalog/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(DailyCatalog entity) {
        dailyCatalogService.saveOrUpdate(entity);
        return "redirect:/dailyCatalog/list.do";
    }

    @RequestMapping("/listCatalogByDailyId")
    @ResponseBody
    public Object listCatalogByDailyId(Long dailyId) {
        return dailyCatalogService.listCatalogByDailyId(dailyId);
    }
}
